<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/css/my-css.css" />
    <script type="text/javascript" src="/js/my-js.js" ></script>
    <script type="text/javascript" src="/js/vue.min.js" ></script>
    <script type="text/javascript" src="/js/jquery.cookie.js" ></script>
    <title>Java学习网</title>
    <style type="text/css">
        nav {
            font-size: 16px;
            font-family: "微软雅黑";
        }
        .div-content {
            margin-top: 10px;
            margin-bottom: 30px;
            border: 1px solid #EEEEEE;
        }
    </style>
</head>
<body>
    <div id="header"></div>
    <script type="text/javascript">moralLoad("#header", "/html/header.html")</script>
    <div class="container">
        <div class="row">
            <div class="col-xs-offset-1 col-xs-10 panel panel-default div-content">
                <h3><b>添加测试</b></h3>
                <hr />
                <form class="form-horizontal" id="addTest">
                    <div class="form-group">
                        <label for="title" class="col-xs-2 control-label">测试标题</label>
                        <div class="col-xs-5">
                            <input type="text" class="form-control" name="title" id="title" required="required" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="description" class="col-xs-2 control-label">测试简述</label>
                        <div class="col-xs-7">
                            <textarea name="description" id="description" rows="3" class="form-control" style="resize: none;"></textarea>
                        </div>
                    </div>
                    <div style="margin: 20px 0 20px 0; text-align: center;">
                        <p id="message" class="text-danger" style="visibility: hidden;">!</p>
                    </div>
                    <div class="col-xs-offset-2 col-xs-7">
                        <button type="submit" class="pull-left col-xs-4 btn btn-warning">添加</button>
                        <button type="button" class="pull-right col-xs-4 btn btn-primary" onClick="location.href='/login.html'">返回</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript">
    var $addForm = $("#addTest");
    $addForm.submit(function() {
        var test = {
            title: $('#title').val(),
            description: $('#description').val(),
        }
        myAjax({
        	type: 'post',
        	url: '/tests',
        	data: test,
        	success: function() {
        		showMessage("添加成功！");
        		$addForm[0].reset();
        	}
        });
        return false;
    });
</script>
</html>